import 'dart:async';

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:star_unbounded/model/clipboard_data.dart';

typedef OnInputCallback =void Function(String text);

class TextInput extends StatefulWidget {
  final OnInputCallback? onInput;
  final BuildContext? context;
  final TextEditingController textEditingController;
  const TextInput({super.key,this.onInput,this.context,required this.textEditingController});
  @override
  State<TextInput> createState() => _TextInputState();
}

class _TextInputState extends State<TextInput> {


 void listener (){
   if(widget.onInput != null){
     widget.onInput!(widget.textEditingController.text);
   }
 }


 @override
 void initState() {
   // TODO: implement initState
   super.initState();
   widget.textEditingController.addListener(listener);
 }

 @override void dispose() {
   widget.textEditingController.removeListener(listener);
   widget.textEditingController.dispose();
   // TODO: implement dispose
   super.dispose();
 }

  @override
  Widget build(BuildContext context) {
    return  Padding(
      padding:  const EdgeInsets.all(8.0),
      child:  TextField(
            controller:widget.textEditingController,
            decoration: const InputDecoration(
              filled: true
            ),
      ),

    );
  }
}
